package com.blaze.framework.core.util.exception;

import com.blaze.framework.core.util.domain.HttpErrorMessage;
import com.blaze.framework.core.util.domain.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @author created by Zhou Zongbo on 2025/5/22.
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 统一异常处理
     *
     * @param ex ex
     * @return ResponseEntity
     */
    @ExceptionHandler(Exception.class)
    public R<HttpErrorMessage> handleException(Exception ex) {
        HttpErrorMessage error = ExceptionHandlerRegistry.findError(ex);
        return R.fail(error.getStatus(), error.getMessage(), error);
    }
}
